package com.codedef.controller;

import com.codedef.common.response.Result;
import com.codedef.entity.ReservationRecord;
import com.codedef.service.SignInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 孙宏宇
 * @date 2021/2/24 09:29
 */
@RestController
@RequestMapping("/signIn")
public class SignInController {

    @Autowired
    SignInService signInService;

    @GetMapping("/scanQRCodeSignIn/{base}")
    public Result scanQRCodeSignIn(@PathVariable("base") String base, @RequestHeader("USER_ID") String userId) {
        ReservationRecord record = signInService.scanQRCodeSignIn(base, Integer.parseInt(userId));
        if (record != null)
            return Result.SUCCESS(record);
        return Result.FAIL();
    }

    @GetMapping("/qrCodeSignIn/{base}")
    public Result qrCodeSignIn(@PathVariable("base") String base, @RequestHeader("USER_ID") String userId) {
        boolean b = signInService.qrCodeSignIn(base, Integer.parseInt(userId));
        if (b)
            return Result.SUCCESS().setMessage("签到成功");
        return Result.FAIL();
    }

}
